<script setup>
import HomePannel from "./HomePannel.vue";
import {onMounted, ref} from 'vue'
import {findNewAPI} from "@/api/home.js";

const NewList = ref([])
const getNewList = async () => {
  const res = await findNewAPI()
  console.log(res)
  NewList.value = res.result
}

onMounted(() => {
  getNewList()
})
</script>

<template>
  <HomePannel title="新鲜好物" subtitle="新鲜出炉 品质靠谱">
    <!--插槽的主体内容，传递给子组件，子组件通过具名插槽进行接收-->
    <template #main>
      <ul class="goods-list">
        <li v-for="item in NewList" :key="item.id">
          <!--点击该商品时，会跳转到商品详情页，并传递该商品的id-->
          <RouterLink :to="`/detail/${item.id}`">
            <img v-img-lazy="item.picture" alt="">
            <!--<img :src="item.picture" alt=""/>-->
            <p class="name">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </HomePannel>
</template>


<style scoped lang='scss'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .price {
      color: $priceColor;
    }
  }
}
</style>